﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MS.InformationManagement.DAL.DocumentCenter;
using System.Collections.Generic;
using MS.InformationManagement.Presenter.PrestamoDeRadicados;
using MS.InformationManagement.Support;
using MS.InformationManagement.Support.Constants;

namespace MS.InformationManagement.Controls._CONTROLTEMPLATES.InformationManagerControls
{
    public partial class PrestamoDeRadicados : UserControl, IPrestamoDeRadicadosView
    {
        #region fields

        PrestamoDeRadicadosPresenter _presenter;

        #endregion

        #region Properties

        public int CurrentId
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["ID"]))
                    return 0;
                else
                    return int.Parse(Page.Request.QueryString["ID"]);
            }
        }
        public List<SolicitudDePrestamosContentType> Solicitud { get; set; }
        public string ObservacionesPrestamo { get; set; }
        public EstadoDePrestamo Prestamo { get; set; }
        public bool resultUpdate { get; set; }

        #endregion

        #region Form Methods

        protected void Page_Load(object sender, EventArgs e)
        {
            txtObservacion.Required(ExceptionConstants.ERROR_CAMPO_NULO, "ValBtnAddRadicado", AjaxControlToolkit.ValidatorCalloutPosition.BottomRight);
            
            _presenter = new PrestamoDeRadicadosPresenter(this);
            _presenter.CargarSolicitud();
        }

        protected void CloseAction(object sender, EventArgs e)
        {
            this.CloseWindow();
        }

        protected void SaveAction(object sender, EventArgs e)
        {
            ObservacionesPrestamo = txtObservacion.Text;
            switch (RadioButtonList1.SelectedValue) 
            {
                case "1":
                    Prestamo = EstadoDePrestamo.Pendiente;
                    break;
                case "2":
                    Prestamo = EstadoDePrestamo.Rechazado;
                    break;
                default:
                    Prestamo = EstadoDePrestamo.None;
                    break;
            }
            _presenter.GuardarSolicitud();
        }

        protected void gvSolicitud_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Controls[0].Visible = false;
            }
        }
        #endregion

        #region Implemented Methods

        public void Show()
        {
            gvSolicitud.DataSource = Solicitud;
            gvSolicitud.DataBind();
            
        }

        public void UpdateSolicitudResult()
        {
            if (resultUpdate == true)
            {
                this._ShowAlertAndClose("Su solicitud ha sido registrada");
            }
            else
            {
                this._ShowAlertAndClose("Ha ocurrido un error al ingresar su solicitud");
            }
            
        }

        #endregion

       

        
    }
}
